package mop.controller;
import java.util.List;

import mop.exception.IllegalIdException;
import mop.model.World;
import mop.model.task.Task;
import mop.model.task.TaskInterface;

/**
 * RemoveTaskController
 * 
 * Use case controller for the removal of a task (use case 2)
 * 
 * @author	MOP Team 7
 */
public class RemoveTaskController extends UseCaseController{
	
	/**
	 * Constructor
	 * @see UseCaseController#UseCaseController(World)
	 */
	public RemoveTaskController(World s)
	{
		super(s);
	}
	
	/**
	 * @see		UseCaseController.getUserTasks()
	 */
	public List<TaskInterface> getUserTasks()
	{		
		return super.getUserTasks();
	}
	
	/**
	 * Whether a task can be removed directly
	 * @param t	The id of the task
	 * @return	True if task has no parents, false otherwise
	 * @throws IllegalIdException	When no task exists with given id
	 * 	|@see this#getTask(String)
	 */
	public boolean canBeRemoved(String t) 
		throws IllegalIdException
	{
		Task task = getTask(t);
		if(task.getParentList().size() > 0)
			return false;
		return true;
	}
	
	/**
	 * Remove a task
	 * @param t				The id of the task to be removed
	 * @param removeParents	Whether we need to delete all parents
	 * @throws IllegalIdException	When no task exists with given id
	 * 	|@see this#getTask(String) 
	 * @effect Remove task with direct or all parents
	 */
	public void removeTask(String t, boolean removeParents) 
		throws IllegalIdException
	{
		Task task = getTask(t);
		if(removeParents)
			task.removeRecursive();
		else
			task.removeNonRecursive();
	}

	
	/***************************************************************************
	 * 								Visit
	 ***************************************************************************/
	
	/**
	 * Make a CallBack to the visitor
	 * @param v the visitor
	 */
	public void accept(ControllerVisitor v)
	{
		v.visit(this);
	}
	
	/***************************************************************************
	 * 								Acl
	 ***************************************************************************/
	
	@Override
	public String getAssetId() {
		return "RemoveTask";
	}
	
}
